package net.xuhf.mqtt;

import net.xuhf.conf.MqttProducerConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/send")
public class SendController {

    @Autowired
    private MqttProducerConfig config;

    @GetMapping("/index")
    @ResponseBody
    public String send(int qos, boolean retained, String topic, String message) {
        try {
            config.publish(qos, retained, topic, message);
            return "发送成功";
        } catch (Exception e) {
            e.printStackTrace();
            return "发送失败";
        }
    }

}
